diehard
Diehard is a node.js module that helps you gracefully clean up your program at termination with multiple sync and/or async handlers. Wraps the death
npm module.
Why?
death
is an incredibly useful module that abstracts out the need to handle the various kinds of termination events, but ultimately only supports a single handler. I've found that in more complex projects you often have multiple loose ends to clean up, and I desired a solution that would allow me to properly isolate the responsibility for cleaning up each individual resource into dedicated handlers that would are run in parallel. diehard
solves that problem.
Installation (via npm)
$ npm install diehard
Usage
var diehard = require('diehard');
setInterval(function () {
console.log('Blah blah blah.');
}, 250);
diehard.register(function () {
});
diehard.register(function (done) {
done();
});
diehard.register(function (signal, done) {
done();
});
diehard.register(function (signal, uncaughtErr, done) {
done();
});
diehard.listen();
In the above example, all five termination handlers will be run (in parallel) before the process exits.
License
MIT License
Author
Troy Goode (troygoode@gmail.com)